# coding = utf-8

# 导入UI工具包
from tkinter import *
import tkinter.messagebox as messagebox


# 具体窗体作用展现
class TkDemo():
    def __init__(self):
        master = Tk()
        master.title('TK-Python—线程模拟')

        # 菜单栏:
        # 创建菜单栏 (Menu)
        menubar = Menu(master)
        master.config(menu=menubar)
        # 创建设置下拉菜单
        filemenu = Menu(menubar, tearoff=0)
        menubar.add_cascade(label="设置", menu=filemenu)
        filemenu.add_command(label="Thread配置",command=self.set)
        # 创建关于下拉菜单
        editmenu = Menu(menubar, tearoff=0)
        menubar.add_cascade(label="关于", menu=editmenu)
        editmenu.add_command(label="武功秘籍", command=self.guanyu)

        # 进程栏
        # "创建进程\停止进程" 放在的frame1中 (Frame)
        frame1 = Frame(master)
        frame1.pack(fill=X)
        # 按钮"创建进程" (Button)
        getname = Button(frame1, text='创建进程', command=self.start_thread)
        getname.grid(row=1, column=3)
        # 按钮"停止进程" (Button)
        getname = Button(frame1, text='停止进程', command=self.stop_thread)
        getname.grid(row=1, column=6)

        # Thread状态栏---运行态\就绪态\阻塞态
        frame3 = Frame(master)
        frame3.pack(fill=X)
        # 运行态标签
        label1 = Label(frame3, text='运行态:')
        label1.grid(row=0, column=0)
        # 运行态列表  (Listbox)
        self.listbox = Listbox(frame3)
        self.listbox.grid(row=3, column=0)
        # Thread状态栏---就绪态
        # 就绪态标签
        label2 = Label(frame3, text='就绪态:')
        label2.grid(row=0, column=4)
        # 就绪态列表  (Listbox)
        self.listbox = Listbox(frame3)
        self.listbox.grid(row=3, column=4)
        # Thread状态栏---阻塞态
        # 阻塞态标签
        label3 = Label(frame3, text='阻塞态:')
        label3.grid(row=0, column=8)
        # 阻塞态列表  (Listbox)
        self.listbox = Listbox(frame3)
        self.listbox.grid(row=3, column=8)
        master.mainloop()



  # 属性
    def set(self):
        pass
    def guanyu(self):# 暂时还未优化窗体大小适宜风格
        master1 = Tk()
        master1.title('武功秘籍')
        title = Label(master1, text='要练此功，必先自宫', font='15', bg='white', fg='red')
        title.pack()

    def start_thread(self):
        pass

    def stop_thread(self):
        pass
    # 文件栏
    def newfile(self):
        self.file = open(r'test.txt', 'w')
        self.file.close()
        messagebox.showinfo('新建文件','您已成功创建个人资料文档')   # 显示对话框
    def openfile(self):
        f = open(r'test.txt', 'r')
        try:
            f_read=f.read()
            #f_read_decode=f_read.decode('utf-8')
            print(f_read)
        finally:
            f.close()
    def savefile(self):
        messagebox.showwarning('保存文件', '亲，提交即保存哦！')    # 显示对话框

    # 编辑栏
    def red(self):
        self.group['bg'] = 'red'
    def blue(self):
        self.group['bg'] = 'blue'
    def yellow(self):
        self.group['bg'] = 'yellow'
    def nomal(self):
        self.group['bg'] = 'SystemButtonFace'

    # 帮助栏
    def description(self):
        messagebox.showinfo('Description', '1.新建您的个人资料\n2.填写调查问卷\n3.点击提交 ')   # 显示对话框
    def about(self):
        messagebox.showinfo('about', '本调查问卷是python小白建文大帝用来学习TK模块的，涵盖TK模块所有GUI界面 \n                                                              ----1.0版')   # 显示对话框

    # 名字
    def getname(self):
        name = self.name.get()
        print(name)

    # 性别
    def getsex(self):
        sex = self.sex.get()
        print(sex)

    # 年龄
    def getage(self):
        print(self.age.get())

    # 语言
    def getlanguage(self):
        print(self.listbox.get(0, END))

    # 图案
    def displayRect(self):
        self.canvas.create_rectangle(10, 10, 190, 90, tags = "rect")
        self.pattern = '长方形'
    def displayOval(self):
        self.canvas.create_oval(10, 10, 190, 90, tags = "oval", fill = "red")
        self.pattern = '椭圆'
    def displayArc(self):
        self.canvas.create_arc(10, 10, 190, 90, start = 0, extent = 90, width = 8, fill = "red", tags = "arc")
        self.pattern = '圆弧'
    def displayPolygon(self):
        self.canvas.create_polygon(10, 10, 190, 90, 30, 50, tags = "polygon")
        self.pattern = '多边形'
    def displayLine(self):
        self.canvas.create_line(10, 10, 190, 90, fill = 'red', tags = "line")
        self.canvas.create_line(10, 90, 190, 10, width = 9, arrow = "last", activefill = "blue", tags = "line")
        self.pattern = '线'
    def displayString(self):
        self.canvas.create_text(60, 40, text = "您真棒！！！", font = "Tine 10 bold underline", tags = "string")
        print(self.pattern)
    def clearCanvas(self):
        self.canvas.delete("rect", "oval", "arc", "polygon", "line", "string")

    # 球星
    def getstar(self):
        print(self.listbox2.get(ACTIVE))

    # 数字
    def getnumber(self):
        print(self.number.get())

    # 同意
    def getagree(self):
        print(self.agree.get())

    # 提交
    def allsubmit(self):
        with open(r'test.txt', 'w') as f:
            f.write('您的花名是：')
            f.write(self.name.get())
            f.write('\n您的性别为:')
            f.write(self.sex.get())
            f.write('\n您的年龄是：')
            f.write(str(self.age.get()))
            f.write('\n您会这么多编程语言：')
            for i in self.listbox.get(0, END):
                f.write(i)
                f.write(" ,")
            f.write('\n您喜欢的图案是：')
            f.write(self.pattern)
            f.write('\n您喜欢的球星号为：')
            f.write(self.listbox2.get(ACTIVE))
            f.write('\n您喜欢的数字为：')
            f.write(self.number.get())
            f.write('\n')
            f.write(self.agree.get())
            f.write('本调查问卷的真实性')
        messagebox.showinfo('Success', '恭喜您已成功提交 ')   # 显示对话框

TkDemo()